package com.ctl.jvm;

/**
 * <p>Title: EvictingQueue</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2019</p>
 * <p>Company: www.ctl.com</p>
 *
 * @author ctl
 * @version 1.1
 * @date 2024-07-04 09:42
 */

import com.ctl.juc.ThreadPoolExecutors;
import com.google.common.collect.EvictingQueue;

public class EvictingQueueTest {

    public static void main(String[] args) {
        /**
         * Guava EvictingQueue：默认情况下不是线程安全的，需要手动同步或者结合其他线程安全的机制来使用。
         */
        EvictingQueue<Integer> queue = EvictingQueue.create(5);

        for (int i = 0; i < 20; i++) {
            int finalI = i;
            ThreadPoolExecutors.threadPoolExecutor.execute(()->{
                queue.add(finalI);
                System.out.println("Queue content: " + queue);
            });

        }
    }

}
